/*
 * @Author       : wfl
 * @LastEditors  : wfl
 * @description  :
 * @updateInfo   :
 * @Date         : 2023-08-11 11:15:07
 * @LastEditTime : 2023-10-27 14:01:31
 */
import useSettingsStore from '@g/store/modules/settings'
import useMenuStore from '@g/store/modules/menu'
import router from '@g/router'

export default function useMenu() {
  const settingsStore = useSettingsStore()
  const menuStore = useMenuStore()

  function switchTo(index: number | string, item?: any) {
    const link = item?.link || item?.meta?.link || item?.path
    if (link?.startsWith('http')) {
      window.open(link)
      return
    }
    menuStore.setActived(index)
    if (settingsStore.settings.menu.switchMainMenuAndPageJump)
      router.push(menuStore.sidebarMenusFirstDeepestPath)
  }

  return {
    switchTo
  }
}
